package daily.year2024.m8;

import java.util.ArrayList;
import java.util.List;

public class d10 {
    class Solution {
        //找出所有元音字符的下标
        public String reverseVowels(String s) {
            char[] chars = s.toCharArray();
            List<Integer> indexs = new ArrayList<>();
            int n = chars.length;
            for(int i=0;i < n;i++) {
                if(testIfVowels(chars[i])) {
                    indexs.add(i);
                }
            }
            int half = indexs.size() / 2;
            for(int i=indexs.size()-1;i >= half;i--) {
                int idx1 = indexs.get(i);
                int idx2 = indexs.get(indexs.size()-1-i);
                char tmp = chars[idx1];
                chars[idx1] = chars[idx2];
                chars[idx2] = tmp;
            }
            return new String(chars);
        }

        private boolean testIfVowels(char c) {
            if(c <= 90) {
                c = (char)(c + 32);
            }
            return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
        }
    }
}
